//
//  FXStatus.swift
//  微博(Swift)
//
//  Created by V on 16/1/2.
//  Copyright © 2016年 V. All rights reserved.
//

import UIKit

class FXStatus: NSObject {
    /// 微博的内容
    var text: String?
    /// 微博的创建时间
    var created_at: String?
    /// 微博的来源
    var source: String?
    /// 当前微博的作者信息
    var user: FXUser?
    /// 转发微博的字段
    var retweeted_status: FXStatus?
    /// 转发评论赞 的数量
    var reposts_count: Int = 0
    var comments_count: Int = 0
    var attitudes_count: Int = 0
    // 配图视图需要的数据
    var pic_urls: [FXStatusPictureInfo]?
    // 当前微博的ID
    var id: Int64 = 0
    
    
    
        
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            if let dict = value as? [String: AnyObject]{
                // user 中存储的是 FXUser 模型
                user = FXUser(dict: dict)
            }
        }else if key == "retweeted_status" {
            if let dict = value as? [String: AnyObject]{
                retweeted_status = FXStatus(dict: dict)
            }
        }else if key == "pic_urls" {
            // pic_urls 是一个数组，数组中存放的是字典，一个图片对应一个字典
            // 初始化一个配图数据的数组
            pic_urls = [FXStatusPictureInfo]()
            if let dicts = value as? [[String: AnyObject]]{
                for dict in dicts {
                    let pictureInfo = FXStatusPictureInfo(dict: dict)
                    pic_urls?.append(pictureInfo)
                }
            }
        }else{
            // 在此一定要调用 super ，因为 super 方法才是真正赋值
            super.setValue(value, forKey: key)
        }
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
    
    }
    
    
    
}
